package com.yalemang.photovalut.base.dialog

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.yalemang.photovalut.base.R

class BottomDialogAdapter(private var tabs: ArrayList<CommonBottomDialog.Tab>): RecyclerView.Adapter<BottomDialogAdapter.BottomDialogHolder>() {

    lateinit var itemClickListener: ItemClickListener

    interface ItemClickListener{
        fun click(tab: CommonBottomDialog.Tab)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BottomDialogHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_bottom_dialog,parent,false)
        return BottomDialogHolder(view)
    }

    override fun getItemCount(): Int {
        return tabs.size
    }

    override fun onBindViewHolder(holder: BottomDialogHolder, position: Int) {
        val tab = tabs[position]
        holder.tv.text = tab.content
        holder.itemView.setOnClickListener{
            if (this::itemClickListener.isInitialized) {
                itemClickListener.click(tab)
            }
        }
    }

    class BottomDialogHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var tv: TextView

        init {
            tv = itemView.findViewById(R.id.tv_item_bottom)
        }
    }
}